package com.simou.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.simou.pojo.Role;
import com.simou.service.RoleServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.websocket.server.PathParam;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class RoleController {
    @Autowired
    RoleServiceImpl roleService;

    @RequestMapping("/user/getrolelist")
    @ResponseBody
    public String getRoleList(@PathParam("method") String method) throws JsonProcessingException {
        System.out.println("user/getrolelist的method："+ method);
        List<Role> roleList = roleService.getAllRoles();
        ObjectMapper objectMapper = new ObjectMapper();
        // 返回json数据
        return objectMapper.writeValueAsString(roleList);
    }

    public List<Role> getRoleList(){
        return roleService.getAllRoles();
    }
}
